***Curtis RESTAT
***This do file generates the summary statisitcs found in table 1 of the paper
**Change to directory where data and code was downloaded


*cd /*   */
    pause on
    set more off
    clear all
    set mem 1G
    *#delimit 



cd "/Users/Curtis/Dropbox/Restat2017/Table1/data"
*summary stats by worker age can be calculated by using below datasets
*local groups qwi_all qwi_A02 qwi_A03 qwi_A04 qwi_A05 qwi_A06 qwi_A07 qwi_A08 
local out_vars lemp hires_rate seps_rate nempsep learnhirns learns  /*crs_rate des_rate lhiras lseps nempsep earnsepc lemps turnovrs learns lpayroll*/


set matsize 10000
use "qwi_all_table1.dta",clear

qui do qwi_dataprep_table1.do

unique state
gen lemps=ln(emps+1)
gen lemp=ln(emp+1)
gen lhiras=ln(hiras)
gen lseps=ln(seps)
gen hires_rate=hiras/emp_base
gen sep_rate=sep/emp_base
gen hire_rate=hira/emp_base
gen seps_rate=seps/emp_base
gen cr_rate=frmjbgn/emp_base
gen de_rate=frmjbls/emp_base
gen crs_rate=frmjbgns/emp_base
gen des_rate=frmjblss/emp_base
gen learns=ln(earns)
gen learnhirns=ln(earnhirns)
gen lpayroll=ln(payroll)
rename naics3 naics

collapse (mean) hires_rate seps_rate nempsep earns earnhirns ,by(naics)
so naics

save tempqwi,replace

clear

set matsize 1500
clear all
set more off

*** uses employment data from CBP
use cbp_all_table1,clear

drop if enint==0 /*keeps only MFTG Industries*/
drop if fipstate=="11" /*Drops DC*/

do cbp_dataprep_table1.do

collapse (mean) enint emp ,by(naics)
so naics

save tempcbp,replace
clear

insheet using ind_names_table1.csv,comma
rename naics3digitcode naics
tostring naics,replace
so naics
merge 1:1 naics using tempcbp
drop _m
merge 1:1 naics using tempqwi
drop if naics==""
drop _m

***The resulting dataset contains the summary stats found in table 1 of the paper


